﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using RestSharp;

namespace Web.MVC.Helper
{
    /// <summary>
    /// 通过Gateway调用服务
    /// </summary>
    public class GatewayServiceHelper:IServiceHelper
    {
        private MyServerInfo m_MyServerInfo;
        private readonly ILogger<GatewayServiceHelper> _logger;
        public GatewayServiceHelper(ILogger<GatewayServiceHelper> logger,IOptions<MyServerInfo> options )
        {
            m_MyServerInfo = options.Value;
            _logger = logger;
            _logger.LogInformation($"MyServerInfo:GateWayBaseAddress:{m_MyServerInfo.GateWayBaseAddress}");

            
        }
        public async Task<string> GetProduct()
        {
            var client = new RestClient(m_MyServerInfo.GateWayBaseAddress);
            var request = new RestRequest("/products", Method.GET);

            var response = await client.ExecuteAsync(request);
            return response.Content;
        }

        public async Task<string> GetOrder()
        {
            var client = new RestClient(m_MyServerInfo.GateWayBaseAddress);
            var request = new RestRequest("/orders", Method.GET);

            var response = await client.ExecuteAsync(request);
            return response.Content;
        }

        public void GetServices()
        {
            throw new NotImplementedException();
        }
    }
}
